package com.my.h2;


import com.my.h2.test.H2Dao;
import com.my.h2.test.User;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
/**
 * @author timo 2021/3/11
 */
@RunWith(SpringRunner.class)
@SpringBootTest(classes = H2Test.class,webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
//因为没有启动类注解@SpringBootApplication，在这里的测试类需要这个注解才能正常运行，不然会报
//Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean
@EnableAutoConfiguration
public class H2Test {
    @Autowired
    private H2Dao H2Service;

    @Test
    public void testGetUserAll(){
        Iterable<User>userIterable=H2Service.findAll();
        for(User user:userIterable){
            System.out.println("查询到用户名为："+user.getName()+"的电话为："+user.getPhone());
        }
    }

}
